package cn.clq.cxfspringboot.config;

import cn.clq.cxfspringboot.service.UserService;
import cn.clq.cxfspringboot.service.impl.UserServiceImpl;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class CXFConfig {

    /**
     * 拦截路径
     * @return
     */
    @Bean
    public ServletRegistrationBean disp(){
        return new ServletRegistrationBean(new CXFServlet(), "/test/*");
    }

    /**
     * CXF的总线
     * @return
     */
    @Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus() {
        return new SpringBus();
    }
    //创建bean
    @Bean
    public UserService userService() {
        return new UserServiceImpl();
    }

    /**
     * 注册接口 /user 路径
     * @return
     */
    @Bean
    public EndpointImpl endpoint() {
        EndpointImpl endpoint = new EndpointImpl(springBus(), userService());
        endpoint.publish("/user");
        return endpoint;
    }
}
